package stream;

import java.util.Arrays;
import java.util.List;

/**
 * 检测流中元素是否匹配要求
 */
public class StreamMatch {
    public static void main(String[] args) {
        allMatch();
        anyMatch();
        nonMatch();
    }

    private static void nonMatch() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        boolean b = list.stream().noneMatch(i -> i > 6);
        System.out.println("b = " + b); // true
    }

    private static void anyMatch() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        boolean b = list.stream().anyMatch(i -> i > 2);
        System.out.println("b = " + b); // true
    }

    private static void allMatch() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        boolean b = list.stream().allMatch(i -> i > 2);
        System.out.println("b = " + b); // false
    }
}
